﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace DS.SludgeEngine.Base.GlobalContent
{
    [Serializable]
    [XmlRoot()]
    public class ContentConfiguration
    {
        [XmlArray("ContentGroups")]
        [XmlArrayItem("ContentGroup")]
        public List<ContentGroup> Groups
        {
            get;
            set;
        }
       
        public static ContentConfiguration Deserialise(string xml)
        {
            XmlSerializer serialiser = new XmlSerializer(typeof(ContentConfiguration));
            MemoryStream stream = new MemoryStream();
            stream.Write(Encoding.ASCII.GetBytes(xml), 0, xml.Length);
            stream.Position = 0;
            return serialiser.Deserialize(stream) as ContentConfiguration;
        }
    }

    public class ContentGroup
    {
        [XmlAttribute()]
        public string Name
        {
            get;
            set;
        }

        [XmlArray("ContentItems")]
        [XmlArrayItem("ContentItem")]
        public List<ContentItem> ContentItems
        {
            get;
            set;
        }

    }
    public class ContentItem
    {
        [XmlAttribute()]
        public string ContentKey
        {
            get;
            set;
        }

        [XmlAttribute()]
        public string FileLocation
        {
            get;
            set;
        }

        [XmlAttribute()]
        public string ContentType
        {
            get;
            set;
        }

    }
}
